//
//  DGGMobileLoginViewController.m
//  DGGMobileLoginSDK
//
//  Created by dgg_hzk on 2019/12/16.
//

#import "DGGMobileLoginViewController.h"
#import "DGGTelecomLoginViewController.h"
#import <Masonry/Masonry.h>
#import "DGGMobileLoginServiceViewController.h"
#import <NTESQuickPass/NTESQuickPass.h>
#import <VerifyCode/NTESVerifyCodeManager.h>
#import "DGGMobileLoginSDKPrefixHeader.h"

@interface DGGMobileLoginViewController ()<NTESQuickLoginManagerDelegate,NTESVerifyCodeManagerDelegate>

@property (nonatomic, strong) UIActivityIndicatorView *activityIndicator;

@end

@implementation DGGMobileLoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    [NTESQuickLoginManager sharedInstance].delegate = self;
    [self preGetPhoneNumber];
}

#pragma mark - 预取号操作
- (void)preGetPhoneNumber{
    [self.activityIndicator startAnimating];
    __weak typeof(self)weakSelf = self;
    [[NTESQuickLoginManager sharedInstance] getPhoneNumberCompletion:^(NSDictionary * _Nonnull resultDic) {
        NSNumber *boolNum = [resultDic objectForKey:@"success"];
        BOOL success = [boolNum boolValue];
        if (success) {
            [self configChinaMobileAuthPageModel];
            [self authorizeChinaMobile];
        } else {
            [self dismissViewControllerAnimated:YES completion:^{
                [weakSelf handleLoginStatus:DGGMobileLoginStatusPreGetPhoneFailure accessToken:nil result:resultDic];
            }];
        }
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [self.activityIndicator stopAnimating];
        });
    }];
    
}

#pragma mark - 回调信息统一处理
- (void)handleLoginStatus:(DGGMobileLoginStatus)status accessToken:(NSString *)accessToken result:(NSDictionary *)result{
    //NSString *quickPassToken = [DGGMobileLoginSDK sharedInstance].loginBusinessId;
    NSString *quickPassToken = @"";
    if([self.delegate respondsToSelector:@selector(dgg_mobileLoginResponseStatus:accessToken:quickPassToken:result:)]){
        [self.delegate dgg_mobileLoginResponseStatus:status accessToken:accessToken quickPassToken:quickPassToken result:result];
    }
}

#pragma mark - 移动号码认证/页面配置
- (void)configChinaMobileAuthPageModel{
    NTESQuickLoginModel *CMModel = [[NTESQuickLoginModel alloc] init];
    CMModel.currentVC = self;
    CMModel.authWindowPop = NTESAuthWindowPopFullScreen;
    CMModel.faceOrientation = UIInterfaceOrientationPortrait;
    CMModel.navBgColor = [DGGMobileLoginConfig sharedInstance].navColor;
    CMModel.navTextColor = [DGGMobileLoginConfig sharedInstance].navTextColor;
    
//    NSString *title = [DGGMobileLoginConfig sharedInstance].navTitle;
//    NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:title];
//    [attrStr addAttribute:NSForegroundColorAttributeName value:[DGGMobileLoginConfig sharedInstance].navTextColor range:NSMakeRange(0, title.length)];
    ///导航栏
    CMModel.navText = [DGGMobileLoginConfig sharedInstance].navTitle;
    CMModel.navTextColor = [DGGMobileLoginConfig sharedInstance].navTextColor;
    CMModel.navTextFont = [DGGMobileLoginConfig sharedInstance].navTextFont;
    CMModel.navReturnImg = [DGGMobileLoginConfig sharedInstance].navBackImage;
    CMModel.backActionBlock = ^{
        [self dismissViewControllerAnimated:NO completion:^{
            [self handleLoginStatus:DGGMobileLoginStatusCancel accessToken:nil result:nil];
        }];
        NSLog(@"backAction===返回按钮点击");
    };
    
    ///登录按钮
    CMModel.logBtnText = [DGGMobileLoginConfig sharedInstance].loginButtonText;
    CMModel.logBtnTextFont = [DGGMobileLoginConfig sharedInstance].loginButtonTextFont;
    CMModel.logBtnTextColor = [DGGMobileLoginConfig sharedInstance].loginButtonTextColor;
    CMModel.logBtnUsableBGColor = [DGGMobileLoginConfig sharedInstance].loginButtonBgColor;
    CMModel.logBtnOffsetTopY = [DGGMobileLoginConfig sharedInstance].loginButtonOffsetY;
    CMModel.logBtnHeight = [DGGMobileLoginConfig sharedInstance].loginButtonHeight;
    CMModel.colors = [DGGMobileLoginConfig sharedInstance].loginButtonBgGradientColors;
    CMModel.logBtnRadius = [DGGMobileLoginConfig sharedInstance].logBtnRadius;
    CMModel.logBtnEnableImg = [DGGMobileLoginConfig sharedInstance].logBtnEnableImg;
    CMModel.logBtnHighlightedImg = [DGGMobileLoginConfig sharedInstance].logBtnHighlightedImg;
   
    ///logo
    UIImage *logoImage = [DGGMobileLoginConfig sharedInstance].appLogoImage;
    if(logoImage){
        CMModel.logoImg = logoImage;
    }
    CMModel.logoOffsetTopY = [DGGMobileLoginConfig sharedInstance].appLogoOffsetY;
    CMModel.logoWidth = [DGGMobileLoginConfig sharedInstance].appLogoWidth;
    CMModel.logoHeight = [DGGMobileLoginConfig sharedInstance].appLogoWidth;
    
    ///电话号码
    CMModel.numberOffsetTopY = [DGGMobileLoginConfig sharedInstance].numberOffsetY;
    CMModel.numberFont = [DGGMobileLoginConfig sharedInstance].numberFont;
    CMModel.numberHeight = [DGGMobileLoginConfig sharedInstance].numberHeight;
    
    ///品牌
    CMModel.brandFont = [DGGMobileLoginConfig sharedInstance].brandFont;
    CMModel.brandOffsetTopY = [DGGMobileLoginConfig sharedInstance].brandOffsetY;
    CMModel.brandBackgroundColor = [UIColor clearColor];
    CMModel.brandHeight = [DGGMobileLoginConfig sharedInstance].brandHeight;
    CMModel.brandColor = [DGGMobileLoginConfig sharedInstance].brandColor;
    
    ///复选框
    CMModel.checkedHidden = [DGGMobileLoginConfig sharedInstance].checkedHidden;
    CMModel.uncheckedImg = [DGGMobileLoginConfig sharedInstance].uncheckedImg;
    CMModel.checkedImg = [DGGMobileLoginConfig sharedInstance].checkedImg;
    CMModel.privacyState = [DGGMobileLoginConfig sharedInstance].privacyState;
    CMModel.checkboxWH = [DGGMobileLoginConfig sharedInstance].checkboxWH;
    CMModel.checkBoxAlignment = NSCheckBoxAlignmentTop;
    

    
//    UIImage *imageOne = [self createImageWithColor:[DGGMobileLoginConfig sharedInstance].loginButtonBgColor RectSize:CGSizeMake(180, 40) CornerRadius:10.0f];
//    UIImage *imageTwo = [self createImageWithColor:[[DGGMobileLoginConfig sharedInstance].loginButtonBgColor colorWithAlphaComponent:0.5] RectSize:CGSizeMake(200, 40) CornerRadius:10.0f];
//    CMModel.logBtnImgs = @[imageOne, imageOne, imageTwo];
    
    
//    CMModel.switchAccText = switchText;
    CMModel.customViewBlock = ^(UIView * _Nullable customView) {
    //        customView.backgroundColor = [UIColor blackColor];
            
        ///其他登录方式
        NSMutableAttributedString *switchText = [[NSMutableAttributedString alloc] initWithString:[DGGMobileLoginConfig sharedInstance].switchBtnText];
        [switchText addAttributes:@{NSForegroundColorAttributeName:[DGGMobileLoginConfig sharedInstance].switchBtnTextColor,
                                    NSFontAttributeName:[DGGMobileLoginConfig sharedInstance].switchBtnFont
        } range:NSMakeRange(0, switchText.length)];
    
        UILabel *otherLabel = [[UILabel alloc] init];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelTapped)];
        [otherLabel addGestureRecognizer:tap];
        otherLabel.userInteractionEnabled = YES;
        otherLabel.attributedText = switchText;
        otherLabel.textAlignment = NSTextAlignmentCenter;
        [customView addSubview:otherLabel];
        [otherLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(customView);
            make.top.equalTo(customView).mas_offset([DGGMobileLoginConfig sharedInstance].swithAccOffsetY);
            make.height.mas_equalTo(16);
        }];
    };
    //配置其他协议
    NSMutableString *appPrivacyStr = [NSMutableString stringWithString:[DGGMobileLoginConfig sharedInstance].appPrivacyPrefix];
    NSArray *appPrivacyOriginArray = [DGGMobileLoginConfig sharedInstance].appPrivacyArray;
    NSInteger agreeMentCount = appPrivacyOriginArray.count;
    NSMutableArray *appPrivacyArray = @[].mutableCopy;
    for (int i = 0; i < agreeMentCount; i++) {
        DGGAgreementListModel *model = appPrivacyOriginArray[i];
        if(i == (agreeMentCount - 1)){
//            if(model.webTitle && ![model.webTitle isEqualToString:@""]){
//                [appPrivacyStr appendFormat:@"和%@", model.webTitle];
//            }else{
//                [appPrivacyStr appendFormat:@"和%@", model.title];
//            }
            [appPrivacyStr appendFormat:@"和%@", model.title];
            CMModel.appSPrivacyTitleText = model.webTitle;
            CMModel.appSPrivacyText = model.title;
            CMModel.appSPrivacyURL = model.urlString;
        }else{
//            if(model.webTitle && ![model.webTitle isEqualToString:@""]){
//                [appPrivacyStr appendFormat:@"、%@", model.webTitle];
//
//            }else{
//                [appPrivacyStr appendFormat:@"、%@", model.title];
//            }
            if (i != 0) {
                [appPrivacyStr appendFormat:@"、%@", model.title];
            }else{
                [appPrivacyStr appendFormat:@"%@", model.title];
            }
            
            CMModel.appFPrivacyTitleText = model.webTitle;
            CMModel.appFPrivacyText = model.title;
            CMModel.appFPrivacyURL = model.urlString;
        }
        if(model.webTitle && model.urlString){
            NSAttributedString *tempStr = [[NSAttributedString alloc] initWithString:model.webTitle attributes:@{NSLinkAttributeName:model.urlString}];
            [appPrivacyArray addObject:tempStr];
        }else if(model.title && model.urlString){
            NSAttributedString *tempStr = [[NSAttributedString alloc] initWithString:model.title attributes:@{NSLinkAttributeName:model.urlString}];
            [appPrivacyArray addObject:tempStr];
        }
    }
    [appPrivacyStr appendString:[DGGMobileLoginConfig sharedInstance].appPrivacySuffix];
    CMModel.appPrivacyText = appPrivacyStr;
    CMModel.privacyColor = [DGGMobileLoginConfig sharedInstance].appPrivacyContentColor;
    CMModel.protocolColor = [DGGMobileLoginConfig sharedInstance].appPrivacyColor;
    CMModel.privacyFont = [UIFont systemFontOfSize:12];
    
//    CMModel.appPrivacyDemo = [[NSAttributedString alloc]initWithString:appPrivacyStr attributes:@{NSForegroundColorAttributeName:UIColor.blackColor}];
//    CMModel.appPrivacy = appPrivacyArray;
            
    [[NTESQuickLoginManager sharedInstance] setupModel:CMModel];
}

- (void)authorizeChinaMobile{
    [[NTESQuickLoginManager sharedInstance] CUCMCTAuthorizeLoginCompletion:^(NSDictionary * _Nonnull resultDic) {
        NSNumber *boolNum = [resultDic objectForKey:@"success"];
        BOOL success = [boolNum boolValue];
        if (success) {
            NSString *token = [resultDic objectForKey:@"accessToken"];
            __weak typeof(self) weakSelf = self;
            if(self.presentedViewController){
                [self.presentedViewController dismissViewControllerAnimated:YES completion:^{
                    [weakSelf dismissViewControllerAnimated:NO completion:^{
                        
                    }];
                    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                        [weakSelf handleLoginStatus:DGGMobileLoginStatusSuccess accessToken:token result:resultDic];
                    });
                }];
            }else{
                [self dismissViewControllerAnimated:NO completion:^{
                    [weakSelf handleLoginStatus:DGGMobileLoginStatusSuccess accessToken:token result:resultDic];
                }];
            }
        } else {
//            取消登录:移动返回code码200020，联通返回10104
//            切换登录方式:移动返回code码200060，联通返回10105
            NSString *resultCode = [resultDic objectForKey:@"resultCode"];
            __weak typeof(self) weakSelf = self;
            if ([resultCode isEqualToString:@"200020"] || [resultCode isEqualToString:@"10104"]) {
                //取消登录
                [self dismissViewControllerAnimated:NO completion:^{
                    [weakSelf handleLoginStatus:DGGMobileLoginStatusCancel accessToken:nil result:resultDic];
                }];
            }else if ([resultCode isEqualToString:@"200060"] || [resultCode isEqualToString:@"10105"]) {
                //切换登录方式
                if(self.presentedViewController){
                    [self.presentedViewController dismissViewControllerAnimated:YES completion:^{
                        [weakSelf dismissViewControllerAnimated:NO completion:^{
                            [weakSelf handleLoginStatus:DGGMobileLoginStatusChange accessToken:nil result:resultDic];
                        }];
                    }];
                }else{
                    [self dismissViewControllerAnimated:NO completion:^{
                        [weakSelf handleLoginStatus:DGGMobileLoginStatusChange accessToken:nil result:resultDic];
                    }];
                }
            }
        }
    }];
}

#pragma mark - 登录切换方式
- (void)labelTapped{
    //切换登录方式
    __weak typeof(self) weakSelf = self;
    if(self.presentedViewController){
        __strong typeof(self) strongself = weakSelf;
        [self.presentedViewController dismissViewControllerAnimated:YES completion:^{
            [strongself dismissViewControllerAnimated:NO completion:^{
            }];
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [strongself handleLoginStatus:DGGMobileLoginStatusChange accessToken:nil result:nil];
            });
        }];
    }else{
        __strong typeof(self) strongself = weakSelf;
        [self dismissViewControllerAnimated:NO completion:^{
            [strongself handleLoginStatus:DGGMobileLoginStatusChange accessToken:nil result:nil];
        }];
    }
}

#pragma mark - 旋转菊花
- (UIActivityIndicatorView *)activityIndicator{
    if(!_activityIndicator){
        _activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:(UIActivityIndicatorViewStyleWhiteLarge)];
        _activityIndicator.frame = self.view.bounds;
        _activityIndicator.color = [DGGMobileLoginConfig sharedInstance].pageThemeColor;
        [self.view addSubview:_activityIndicator];
    }
    return _activityIndicator;
}

#pragma mark - 通过颜色生成图片
- (UIImage *)createImageWithColor:(UIColor *)color RectSize:(CGSize)rectSize
                                               CornerRadius:(float)cornerRadius{
    //直接绘制图像方法
//    CGRect rect=CGRectMake(0.0f, 0.0f, 50.0f, 50.0f);
//    UIGraphicsBeginImageContext(rect.size);
//    CGContextRef context = UIGraphicsGetCurrentContext();
//    CGContextSetFillColorWithColor(context, [color CGColor]);
//    CGContextFillRect(context, rect);
//    UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
//    UIGraphicsEndImageContext();
    
    //带圆角图像的绘制方法
    UIImage *theImage;
    CGRect rect = CGRectMake(0.0f, 0.0f, rectSize.width, rectSize.height);
    UIGraphicsBeginImageContext(rect.size);   //开始画线
    [theImage drawInRect:CGRectMake(0, 0, rect.size.width, rect.size.height)];
    //获取上下文
    CGContextRef context = UIGraphicsGetCurrentContext();
    //边框大小
    CGContextSetLineWidth(context, 1);
    //边框颜色
    CGContextSetStrokeColorWithColor(context, [UIColor clearColor].CGColor);
    //矩形填充颜色
    CGContextSetFillColorWithColor(context, [color CGColor]);
    /*
     *
     将要绘制的图像大小,分割成8个点,每两个点可以可以确定一条射线,每两条射线相交处可以设置圆弧.
     当前方法中先绘制的右下角,
     例如,将要绘制的圆角图片大小为:宽100,高100 圆角5,则需要的点分别为:
     A(100,10)
     B(100,100)
     C(90,100)
     D(0,100)
     E(0,90)
     F(0,0)
     G(10,0)
     H(100,0)
     *
    */
    //绘制图像及圆角
    CGContextMoveToPoint(context, rectSize.width, cornerRadius * 2);  // 开始坐标右边开始
    CGContextAddArcToPoint(context, rectSize.width, rectSize.height, rectSize.width - 10, rectSize.height, cornerRadius);  // 右下角
    CGContextAddArcToPoint(context, 0, rectSize.height, 0, rectSize.height - 10, cornerRadius); // 左下角
    CGContextAddArcToPoint(context, 0, 0, cornerRadius * 2, 0, cornerRadius); // 左上角
    CGContextAddArcToPoint(context, rectSize.width, 0, rectSize.width, cornerRadius * 2, cornerRadius); // 右上角
    CGContextDrawPath(context, kCGPathFillStroke); //根据当前坐标绘制路径
    theImage = UIGraphicsGetImageFromCurrentImageContext();//获取绘图
    //拉伸当前图像
    CGFloat h = theImage.size.height * 0.5;
    CGFloat w = theImage.size.width * 0.5;
    UIImage *rsizeImg = [theImage resizableImageWithCapInsets:UIEdgeInsetsMake(h, w, h, w) resizingMode:UIImageResizingModeStretch];
    return rsizeImg;
}

- (void)dealloc{
    NSLog(@"%@ %@", NSStringFromClass(self.class), NSStringFromSelector(_cmd));
}


#pragma mark - NTESQuickLoginManagerDelegate

- (void)authViewWillAppear {
    NSLog(@"授权页面将要弹出");
}

- (void)authViewDidAppear {
    NSLog(@"授权页面已经弹出");
}

- (void)authViewWillDisappear {
    NSLog(@"授权页面将要消失");
}

- (void)authViewDidDisappear {
     NSLog(@"授权页面已经消失");
}

- (void)authViewDidLoad {
     NSLog(@"授权页面初始化了");
}

- (void)authViewDealloc {
    NSLog(@"授权页面销毁了");
    [self.activityIndicator stopAnimating];
    [self dismissViewControllerAnimated:NO completion:^{
    }];
}

#pragma mark - NTESVerifyCodeManagerDelegate
/**
 * 验证码组件初始化出错
 *
 * @param message 错误信息
 */
- (void)verifyCodeInitFailed:(NSString *)message{
    NSLog(@"收到初始化失败的回调:%@",message);
}
/**
 * 完成验证之后的回调
 *
 * @param result 验证结果 BOOL:YES/NO
 * @param validate 二次校验数据，如果验证结果为false，validate返回空
 * @param message 结果描述信息
 *
 */
- (void)verifyCodeValidateFinish:(BOOL)result validate:(NSString *)validate message:(NSString *)message{
    NSLog(@"收到验证结果的回调:(%d,%@,%@)", result, validate, message);
//    if (result) {
//        [self loginSuccess];
//    }
}
/**
 * 网络错误
 *
 * @param error 网络错误信息
 */
- (void)verifyCodeNetError:(NSError *)error{
    //用户关闭验证后执行的方法
    NSLog(@"收到网络错误的回调:%@(%ld)", [error localizedDescription], (long)error.code);
    
}
/**
 * 关闭验证码窗口后的回调
 */
- (void)verifyCodeCloseWindow{
    //用户关闭验证后执行的方法
    NSLog(@"收到关闭验证码视图的回调");
}

#pragma mark - 预约取号老代码
//- (void)preGetPhoneNumber{
//    [self.activityIndicator startAnimating];
//    NSInteger carrier = [[NTESQuickLoginManager sharedInstance] getCarrier];
//    if(carrier == 1){
//        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//            //电信
//            DGGTelecomLoginViewController *loginVC = [[DGGTelecomLoginViewController alloc] init];
//            UINavigationController *rootNav = [[UINavigationController alloc] initWithRootViewController:loginVC];
//            rootNav.modalPresentationStyle = UIModalPresentationFullScreen;
//            [self presentViewController:rootNav animated:YES completion:NULL];
//            __weak typeof(self) weakSelf = self;
//            loginVC.loginAuthResultBlock = ^(NSInteger loginStatus, NSString *accessToken, NSDictionary *errorInfo) {
//                [weakSelf dismissViewControllerAnimated:NO completion:^{
//                    [weakSelf handleLoginStatus:loginStatus accessToken:accessToken result:errorInfo];
//                }];
//            };
//            [self.activityIndicator stopAnimating];
//        });
//    }else if (carrier == 2){
//        //移动
//        __weak typeof(self) weakSelf = self;
//        [[NTESQuickLoginManager sharedInstance] getPhoneNumberCompletion:^(NSDictionary * _Nonnull resultDic) {
//            NSNumber *boolNum = [resultDic objectForKey:@"success"];
//            BOOL success = [boolNum boolValue];
//            if (success) {
//                [self configChinaMobileAuthPageModel];
//                [self authorizeChinaMobile];
//            } else {
//                [self dismissViewControllerAnimated:YES completion:^{
//                    [weakSelf handleLoginStatus:DGGMobileLoginStatusPreGetPhoneFailure accessToken:nil result:resultDic];
//                }];
//            }
//            [self.activityIndicator stopAnimating];
//        }];
//    }else{
//        //联通
//        __weak typeof(self) weakSelf = self;
//        [[NTESQuickLoginManager sharedInstance] getPhoneNumberCompletion:^(NSDictionary * _Nonnull resultDic) {
//            NSNumber *boolNum = [resultDic objectForKey:@"success"];
//            BOOL success = [boolNum boolValue];
//            if (success) {
////                [self configChinaUnicomAuthPageModel];
//                [self configChinaMobileAuthPageModel];
////                [self authorizeChinaUnicom];
//                [self authorizeChinaMobile];
//            } else {
//                [self dismissViewControllerAnimated:YES completion:^{
//                    [weakSelf handleLoginStatus:DGGMobileLoginStatusPreGetPhoneFailure accessToken:nil result:resultDic];
//                }];
//            }
//            [self.activityIndicator stopAnimating];
//        }];
//    }
//}
#pragma mark - 联通号码认证/页面配置
//- (void)configChinaUnicomAuthPageModel{
//    NTESQuickLoginModel *CUModel = [[NTESQuickLoginModel alloc] init];
//    CUModel.currentVC = self;
//    CUModel.controllerType = NTESCUPresentController;
//    CUModel.checkBoxValue= YES;
//    CUModel.navBgColor = [DGGMobileLoginConfig sharedInstance].navColor;
//    CUModel.navTextColor = [DGGMobileLoginConfig sharedInstance].navTextColor;
//    CUModel.navTextFont = [DGGMobileLoginConfig sharedInstance].navTextFont;
//    NSString *loginButtonText = [DGGMobileLoginConfig sharedInstance].loginButtonText;
//    CUModel.logBtnText = loginButtonText;
//    CUModel.navText = [DGGMobileLoginConfig sharedInstance].navTitle;
//    CUModel.navReturnImg = [DGGMobileLoginConfig sharedInstance].navBackImage;
//    CUModel.logBtnUsableBGColor = [DGGMobileLoginConfig sharedInstance].loginButtonBgColor;
//    CUModel.swithAccTextColor = [DGGMobileLoginConfig sharedInstance].switchBtnTextColor;
//    CUModel.switchText = [DGGMobileLoginConfig sharedInstance].switchBtnText;
//    CUModel.privacyTextColor = [DGGMobileLoginConfig sharedInstance].appPrivacyContentColor;
//    CUModel.privacyColor = [DGGMobileLoginConfig sharedInstance].appPrivacyColor;
//    CUModel.swithAccTextAlignment = [DGGMobileLoginConfig sharedInstance].switchBtnTextAlign;
//    CUModel.swithAccOffsetX = [DGGMobileLoginConfig sharedInstance].swithAccOffsetX;
//    CUModel.swithAccOffsetY = [DGGMobileLoginConfig sharedInstance].swithAccOffsetY;
//    UIImage *logoImage = [DGGMobileLoginConfig sharedInstance].appLogoImage;
//    if(logoImage){
//        CUModel.logoImg = logoImage;
//    }
//
//    NSArray *appPrivacyOriginArray = [DGGMobileLoginConfig sharedInstance].appPrivacyArray;
//    //配置其他协议
//    NSInteger agreementCount = appPrivacyOriginArray.count;
//    if(agreementCount > 0){
//        DGGAgreementListModel *model = appPrivacyOriginArray.firstObject;
//        if(model.webTitle && ![model.webTitle isEqualToString:@""]){
//            CUModel.appFPrivacyText = model.webTitle;
//        }else{
//            CUModel.appFPrivacyText = model.title;
//        }
//        CUModel.appFPrivacyText = model.title;
//        CUModel.appFPrivacyURL = [NSURL URLWithString:model.urlString];
//    }
//    if(agreementCount > 1){
//        DGGAgreementListModel *model = [appPrivacyOriginArray objectAtIndex:1];
//        if(model.webTitle && ![model.webTitle isEqualToString:@""]){
//            CUModel.appSPrivacyText = model.webTitle;
//        }else{
//            CUModel.appSPrivacyText = model.title;
//        }
//        CUModel.appSPrivacyURL = [NSURL URLWithString:model.urlString];
//    }
//    [[NTESQuickLoginManager sharedInstance] setupCUModel:CUModel];
//}

//- (void)authorizeChinaUnicom{
//    [[NTESQuickLoginManager sharedInstance] CUCMAuthorizeLoginCompletion:^(NSDictionary * _Nonnull resultDic) {
//        NSNumber *boolNum = [resultDic objectForKey:@"success"];
//        BOOL success = [boolNum boolValue];
//        if (success) {
//            NSString *token = [resultDic objectForKey:@"accessToken"];
//            __weak typeof(self) weakSelf = self;
//            if(self.presentedViewController){
//                [self.presentedViewController dismissViewControllerAnimated:YES completion:^{
//                    [weakSelf dismissViewControllerAnimated:NO completion:^{
//                        [weakSelf handleLoginStatus:DGGMobileLoginStatusSuccess accessToken:token result:resultDic];
//                    }];
//                }];
//            }else{
//                [self dismissViewControllerAnimated:NO completion:^{
//                    [weakSelf handleLoginStatus:DGGMobileLoginStatusSuccess accessToken:token result:resultDic];
//                }];
//            }
//        } else {
//            NSString *resultCode = [resultDic objectForKey:@"resultCode"];
//            __weak typeof(self) weakSelf = self;
//            if ([resultCode isEqualToString:@"10104"]) {
//                //取消登录
//                if(self.presentedViewController){
//                    [self.presentedViewController dismissViewControllerAnimated:YES completion:^{
//                        [weakSelf dismissViewControllerAnimated:NO completion:^{
//                            [weakSelf handleLoginStatus:DGGMobileLoginStatusCancel accessToken:nil result:resultDic];
//                        }];
//                    }];
//                }else{
//                    [self dismissViewControllerAnimated:NO completion:^{
//                        [weakSelf handleLoginStatus:DGGMobileLoginStatusCancel accessToken:nil result:resultDic];
//                    }];
//                }
//            }
//            if ([resultCode isEqualToString:@"10105"]) {
//                //切换登录方式
//                if(self.presentedViewController){
//                    [self.presentedViewController dismissViewControllerAnimated:YES completion:^{
//                        [weakSelf dismissViewControllerAnimated:NO completion:^{
//                            [weakSelf handleLoginStatus:DGGMobileLoginStatusChange accessToken:nil result:resultDic];
//                        }];
//                    }];
//                }else{
//                    [self dismissViewControllerAnimated:NO completion:^{
//                        [weakSelf handleLoginStatus:DGGMobileLoginStatusChange accessToken:nil result:resultDic];
//                    }];
//                }
//            }
//        }
//    }];
//}
@end
